package controller;

import javax.swing.JFrame;

import view.IO;
import view.Menu;
import view.PlanningFrame;
import view.RegistrationFrame;
import view.ScheduleFrame;
import view.TaskFrame;

public class StartupController {
	
	private Menu menu;
	private JFrame planningFrame;
	private JFrame registrationFrame;
	private PlanningController planningController;
	private RegistrationController registrationController;
	private ContainerController containerController;
	/*private JFrame lessenroosterOverzicht;
	private JFrame opdrachtOverzicht;
	private LessenroosterOverzichtController lessenroosterOverzichtController;
	private OpdrachtOverzichtController opdrachtOverzichtController;*/
	
	public StartupController() {
		this.menu = new Menu ("Plan offered courses", "Register for course",
				"Overview planning", "Overview teacher tasks");
		containerController = ContainerController.getInstance();
		this.planningController = PlanningController.getInstance();
		this.registrationController = RegistrationController.getInstance();
	}
	
	/** Entry point of the application */
	public static final void main(String[] args) {
		//ContainerController.getInstance().generateTestData();
		ContainerController.getInstance().readAllData();
		new StartupController().execute();
	}
	
	/** Show application menu */
	public void execute() {
		
		// Get input from user
		int selection = menu.getSelection();
		
		// Open correct frame according to user selection
		switch (selection) {
			case 1:
				planningFrame = new PlanningFrame(this, planningController);
		        planningFrame.setVisible(true);
		        break;
			case 2:
				registrationFrame =new RegistrationFrame(this, registrationController);
				registrationFrame.setVisible(true);
			    break;
			case 3: // Overview planning
				ScheduleFrame scheduleFrame = new ScheduleFrame();
				scheduleFrame.setVisible(true);
			    break;
			case 4: // Overview teacher tasks
				TaskFrame taskFrame = new TaskFrame();
				taskFrame.setVisible(true);
			    break;
			case 5: // Exit + save new objects in text files
				ShutDownController.getInstance().saveData();
			    break;
			default:
			    if (selection != menu.getExitCode()) {
			    	IO.messageDialog("Invalid input");
			    	selection = menu.getSelection();
			    }
		}
	}
}